package com.yvdedu.hospital.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.github.pagehelper.PageInfo;
import com.yvdedu.hospital.entity.Department;
import com.yvdedu.hospital.entity.User;
import com.yvdedu.hospital.entity.tool.DostatTool;
import com.yvdedu.hospital.entity.tool.OutpatiTool;
import com.yvdedu.hospital.entity.tool.StdepTool;
import com.yvdedu.hospital.service.PharmacyService;
import com.yvdedu.hospital.service.RegistrationService;
import com.yvdedu.hospital.service.StatisticsService;

@Controller
@RequestMapping("business/statistics")
public class StatisticsController {
	@Resource
	StatisticsService statisticsService;
	@Resource
	RegistrationService registrationService;
	//挂号查询
	@RequestMapping("query")
	public void query(Model model) {
		String name="";
		int pageNaber = 1;
		List<OutpatiTool> list = statisticsService.outpatientSearch(name,pageNaber);
		PageInfo page = new PageInfo(list);
		model.addAttribute("pageNumber",page.getPageNum());
		model.addAttribute("Pages",page.getPages());
		model.addAttribute("list",list);
	}
	
	//收费查询
	@RequestMapping("monquery")
	public void monquery(Model model) {
		String name="";
		int pageNaber = 1;
		List<OutpatiTool> list = statisticsService.outpatientSearch(name,pageNaber);
		PageInfo page = new PageInfo(list);
		model.addAttribute("pageNumber",page.getPageNum());
		model.addAttribute("Pages",page.getPages());
		model.addAttribute("list",list);
	}
	
	//挂号搜索
	@RequestMapping("serch")
	@ResponseBody
	public Object serch(String name,int pageNaber) {
		System.out.println(name);
		System.out.println(pageNaber);
		List<OutpatiTool> list = statisticsService.outpatientSearch(name,pageNaber);
		System.out.println(list);
		Map<String,Object> map = new HashMap<String,Object>();
		PageInfo page = new PageInfo(list);
		System.out.println(list);
		map.put("pageNmuber", page.getPageNum());
		map.put("pages", page.getPages());
		map.put("list", list);
		return map;
	}
	
	//收费搜索
	@RequestMapping("serch2")
	@ResponseBody
	public Object serch2(String name,int pageNaber) {
		System.out.println(name);
		System.out.println(pageNaber);
		List<OutpatiTool> list = statisticsService.outpatientSearch(name,pageNaber);
		System.out.println(list);
		Map<String,Object> map = new HashMap<String,Object>();
		PageInfo page = new PageInfo(list);
		System.out.println(list);
		map.put("pageNmuber", page.getPageNum());
		map.put("pages", page.getPages());
		map.put("list", list);
		return map;
	}
	
	//科室收入统计
	@RequestMapping("stdep")
	public void stdep(Model model) {
		List<Department> li = registrationService.departmentquery();
		System.out.println(li);
		model.addAttribute("li",li);
	}
	//科室搜索查询
	@RequestMapping("stdepserch")
	@ResponseBody
	public Object stdepserch(String name) {
		System.out.println(name);
		List<StdepTool> list = statisticsService.stedp(name);
		System.out.println(list);
		//总价格
		double money = 0 ;
		//挂号价格
		double fee = 0 ;
		//药品价格
		double amount = 0 ;
		for(int i=0; i<list.size();i++){
			double mon = 0;
			double fe = 0;
			double amoun = 0;
			mon =list.get(i).getAmount()+list.get(i).getFee();
			amoun =list.get(i).getAmount();
			fe =list.get(i).getFee();
			fee+=fe;
			amount+=amoun;
			money+=mon;
		}
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("money", money);
		map.put("amount", amount);
		map.put("fee", fee);
		return map;
	}
	
	//医生统计查询
	@RequestMapping("dostat")
	public void dostat(Model model) {
		int role_id=4;
		List<User> list = statisticsService.userque(role_id);
		System.out.println(list);
		model.addAttribute("list",list);
	}
	
	//医生统计查询
	@RequestMapping("dostatdrech")
	@ResponseBody
	public Object dostatdrech(Model model,String do_name) {
//		String uname = null;
//		String name = null;
		System.out.println(do_name);
		Map<String,Object> map = new HashMap<String,Object>();
//		List<User> lisu = statisticsService.userque(4);
		List<DostatTool> list = statisticsService.dostse(do_name);
//		System.out.println(list);
		for(int i=0; i<list.size();i++){
			double money = list.get(i).getFee()+list.get(i).getAmount();
			String name = list.get(i).getDo_name();
			double fee = list.get(i).getFee();
			double amount = list.get(i).getAmount();
//			System.out.println(name);
//			System.out.println(money);
//			map.put("name"+i, name);
//			map.put("fee"+i, fee);
//			map.put("amount"+i, amount);
//			map.put("money"+i, money);
			map.put("name", name);
			map.put("fee", fee);
			map.put("amount", amount);
			map.put("money", money);
		}
		System.out.println(map);
		return map;
	}

}
 

